<?php

class Resources extends HTech_Db_Table
{
    protected $_name    = 'view_resources';
    protected $_primary = 'ResourceId';
    
    protected $_lnkTables = array('LnkResourcesRoles' => 'RoleId');
    
    protected function _setGridMetadata()
    {
        $this->_gridMetadata['title'] = $this->translate("Resources");
        $this->_gridMetadata['onClick'] = 'admin.resource.view';
        $this->_gridMetadata['headers'] = array
            (
                array('ResourceId',        50, $this->translate("Id"),             'Number'),
                array('Resource',         200, $this->translate("Resource"),       'String'),
                array('Module',           100, $this->translate("Module"),         'String'),
                array('Controller',       200, $this->translate("Controller"),     'String'),
                array('Action',           200, $this->translate("Action"),         'String'),
                array('Public',           100, $this->translate("Public"),         'String'),
                array('LastEditDate',     120, $this->translate("Last edit date"), 'DateTime', 'Date'),
                array('LastEditFullName', 150, $this->translate("Last edit user"), 'String')
            );
        return $this;
    }
    
    protected function _setRecordDependentRows()
    {
        $this->_record->r = (object) array('roles' => null);
        $this->_record->r->roles = $this->_record->d->findManyToManyRowset('Roles','LnkResourcesRoles');   
        array_walk($this->_record->r->roles->toArray(), array($this, '_setRecordLnkData'), array('LnkResourcesRoles', 'RoleId'));   
    }
}